package kr.yoon.practice.serviceUI;

import javax.naming.spi.DirStateFactory.Result;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.JScrollPane;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Panel;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import kr.yoon.practice.db.common.ConnectionFactory;
import kr.yoon.practice.db.dao.DepartmentDAO;
import kr.yoon.practice.db.dto.Department;

import javax.swing.BoxLayout;
import javax.swing.JButton;

import java.awt.ScrollPane;

public class PanelJtable<T> extends JPanel {
	private DepartmentDAO deptDao;
	private JTable table;
	private Panel panel_Center;
	
	private ArrayList<T> lists;
	private String[][] arLists;
	private String[] colNames;
	private int[] fieldSizes;
	
	/**
	 * Create the panel.
	 * @throws SQLException 
	 */
	public PanelJtable() throws SQLException {
		initialize();
	}
		
	private void initialize() throws SQLException {
		Connection con = ConnectionFactory.getConnection();
		deptDao = new DepartmentDAO(con);
		
		setLayout(new BorderLayout(0, 0));
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane);
		
		add(panel_Center);
		String[] colnames = {"부서번호", "부서명", "위치"};
		TableModel model = new DefaultTableModel(colnames, 0);
		table = new JTable();
		panel_Center.add(table);
		table = new JTable(model);
		scrollPane.add(table);
		
		try {
			deptDao.listItems();
			int len = lists.size();
			arLists = new String[len][colnames.length];
			for(int i = 0; i<len; i++){
				if(temp istanceof Employee){
					
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		scrollPane.setViewportView(table);
		
		 
	}

	private void tableCellAlginment() {
		//가운데 정렬
		DefaultTableCellRenderer dtcrCenter = new DefaultTableCellRenderer();
		dtcrCenter.setHorizontalAlignment(SwingConstants.CENTER);
		
		//우측 정렬
		DefaultTableCellRenderer dtcrRight = new DefaultTableCellRenderer();
		dtcrRight.setHorizontalAlignment(SwingConstants.RIGHT);
		//좌측 정렬
		
		DefaultTableCellRenderer dtcrleft = new DefaultTableCellRenderer();
		dtcrleft.setHorizontalAlignment(SwingConstants.LEFT);
		
		TableColumnModel cModel = table.getColumnModel();
		
/*		int columnCount = cModel.getColumnCount();
		cModel.getColumn(0).setPreferredWidth(70);
		cModel.getColumn(0).setCellRenderer(dtcrCenter);*/
	}
	
	public void loadData(){

		
		
	}
	
	

}
